package lzy.impl.smallspring.beans.factory.support;

import lzy.impl.smallspring.beans.factory.config.SingletonBeanRegistry;

import java.util.HashMap;
import java.util.Map;

/**
 * 用于缓存单例对象，但是否需要remove？
 */
public class DefaultSingletonBeanRegistry implements SingletonBeanRegistry {
    private Map<String, Object> singletons = new HashMap<>();

    public Object getSingleton(String beanName) {
        return singletons.get(beanName);
    }

    public void addSingleton(String beanName, Object singleton) {
        singletons.put(beanName, singleton);
    }

    public Object removeSingleton(String beanName) {
        return singletons.remove(beanName);
    }
}
